<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
    <title>${empty salary.id ? '录入新工资' : '编辑工资'}</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css">
</head>
<body>
<div class="container">
    <jsp:include page="header.jsp" />
    <h2>${empty salary.id ? '录入新工资' : '编辑工资'}</h2>
    <form action="${pageContext.request.contextPath}/SalaryServlet" method="post">
        <input type="hidden" name="action" value="${empty salary.id ? 'add' : 'update'}">
        <c:if test="${not empty salary.id}">
            <input type="hidden" name="id" value="${salary.id}">
        </c:if>
        <p>
            <label for="empId">员工:</label>
            <select id="empId" name="empId" required>
                <option value="">--选择员工--</option>
                <c:forEach var="emp" items="${listEmployeeForSalary}">
                    <option value="${emp.id}" ${salary.empId == emp.id ? 'selected' : ''}>
                        <c:out value="${emp.name}"/>
                    </option>
                </c:forEach>
            </select>
        </p>
        <p><label for="salaryYear">年份:</label> <input type="number" id="salaryYear" name="salaryYear" value="${empty salary.salaryYear ? java.time.Year.now().getValue() : salary.salaryYear}" required min="2000" max="2099"></p>
        <p><label for="salaryMonth">月份:</label> <input type="number" id="salaryMonth" name="salaryMonth" value="${empty salary.salaryMonth ? java.time.LocalDate.now().getMonthValue() : salary.salaryMonth}" required min="1" max="12"></p>
        <p><label for="amount">金额:</label> <input type="number" id="amount" name="amount" value="<fmt:formatNumber value='${salary.amount}' type='number' groupingUsed='false' minFractionDigits='2' maxFractionDigits='2'/>" step="0.01" required></p>
        <p>
            <label for="status">状态:</label>
            <select id="status" name="status">
                <option value="未支付" ${salary.status == '未支付' ? 'selected' : ''}>未支付</option>
                <option value="已支付" ${salary.status == '已支付' ? 'selected' : ''}>已支付</option>
            </select>
        </p>
        <p><input type="submit" value="${empty salary.id ? '添加' : '更新'}"></p>
    </form>
    <p><a href="${pageContext.request.contextPath}/SalaryServlet?action=list">返回列表</a></p>
</div>
</body>
</html>
